// 堆代码 duidaima.com
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class AnimatedSwitcherImg extends StatefulWidget {
  AnimatedSwitcherImg({Key? key}) : super(key: key);
  @override
  _AnimatedSwitcherImgState createState() => _AnimatedSwitcherImgState();
}
class _AnimatedSwitcherImgState extends State<AnimatedSwitcherImg> {
  Widget? _animatedWidget;
  bool test = false;
  @override
  void initState() {
    super.initState();
    _animatedWidget = ClipOval(
      child: Image.network('https://static.rarefy.cn/10810010000125/card/image1691771775277.jpg'),
      key: ValueKey(1),
    );
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AnimatedSwticher'),
        backgroundColor: Colors.black, systemOverlayStyle: SystemUiOverlayStyle.light,
      ),
      backgroundColor: Colors.black,
      body: Center(
        child: Container(
          padding: EdgeInsets.all(10.0),

          child: AnimatedSwitcher(
            child: _animatedWidget,
            duration: const Duration(milliseconds: 1000),
            transitionBuilder: (child, animation) {
              return SizeTransition(
                sizeFactor: animation,
                child: child,
              );
            },
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.play_arrow),
        onPressed: () {
          setState(() {
            test = !test;
            _animatedWidget = test
                ? ClipOval(
              child: Image.network('https://static.rarefy.cn/10810010000125/card/image1691651583053.jpg'),
              key: ValueKey(2),
            )
                : ClipOval(
              child: Image.network('https://static.rarefy.cn/10810010000125/card/image1691771775277.jpg'),
              key: ValueKey(1),
            );
          });
        },
      ),
    );
  }
}